% mainFitting.m
% RuiGuo

clear all;
close all;

%.mat path
T1path = 'H:\EXPData\Invivo\20191101\H1\Analysis\MOLLI53\ImgsT1weighted\BeforeLL\MOLLI53_MOCO_Series0029\TxImgsMat\Slice3\';

loadpath = [T1path];

subjectNum ='Patient_1';
datasetnb =2;
sliceNum = 1;
slices = 1;
allSliceTx = [];
for ix = 1:slices
    filename = ['Img' ]; 
    %filename = [ 'Img' ]; 
    %%T1 fitting methods
    switch (datasetnb)
        case 1
            method = 'SASHA';   
        case 2
            method = 'MOLLI';
        case 3
            method = 'T2Fitting' ;
        case 4
            method = 'COSATIRT1Fitting';
    end


    %% Where to save the data
    T1result_dir = ['Tx_' datestr(date,'mm-dd-yyyy') '_' method];
    savepath = [T1path T1result_dir ] ;
    mkdir( savepath );
    loadStr = [loadpath filename];
    saveStr = [savepath filesep 'Tx_'  filename];
    %% Perform fit
    tic
    T1ScanExperiment(loadStr, saveStr, method,sliceNum);
    toc

end

for ix  = 1:slices   
    filename = ['slice' num2str(ix) ]; 
    saveStr = [savepath filesep 'Tx_'  filename];
    load(saveStr);
    allSliceTx(:,:,ix,:)  = T1;
end
%save  T1 of all slices
T1 = allSliceTx;
save( [savepath filesep subjectNum '.mat'], 'T1');

%% display
T1_disp_range =[0 2500];
T2_disp_range = [0 120];
img_arr = [1 1];
%% close all;

f=figure;
hold on
axis off;
imagesc( (squeeze(abs(T1(:,:,1,1)))),T1_disp_range),colormap(jet);
hold off;


f=figure;
hold on;
axis off;
imagesc( squeeze(abs(T1(:,:,1,2))),T2_disp_range),colormap(jet);
hold off;